package service;

import mapper.CourseMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import po.Course;
import po.Result;

import java.util.List;

@Service
public class CourseServiceImpl implements CourseService {
    @Autowired
    private CourseMapper courseMapper;

    @Override
    public List<Course> findCourses(Course course) throws Exception {
        return courseMapper.findCourses(course);
    }

    @Override
    public Result addCourse(Course course) {
        Result result = new Result();
        try {
            courseMapper.addCourse(course);
        } catch (Exception e) {
            result.setResult("fail");
            result.setMessage("添加失败！");
            return result;
        }
        result.setResult("success");
        result.setMessage("添加成功！");
        return result;
    }

    @Override
    public Result deleteCourseByNumber(int number) {
        Result result = new Result();
        try {
            courseMapper.deleteCourseByNumber(number);
        } catch (Exception e) {
            result.setResult("fail");
            result.setMessage("删除失败！");
            return result;
        }
        result.setResult("success");
        result.setMessage("删除成功！");
        return result;
    }

    @Override
    public Result updateCourseByNumber(Course course) {
        Result result = new Result();
        try {
            courseMapper.updateCourseByNumber(course);
        } catch (Exception e) {
            result.setResult("fail");
            result.setMessage("修改失败！");
            return result;
        }
        result.setResult("success");
        result.setMessage("修改成功！");
        return result;
    }
}
